/* @(#)GSAfficheModAction.java    V0.1
 *
 * Project: NEWGS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-5-25
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.HashMap;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.upload.FormFile;

import com.hitrust.gs.bean.GSAfficheBean;
import com.hitrust.gs.business.GSAfficheProcessor;
import com.hitrust.gs.form.GSAfficheForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;

/**
 * 修改公告信息
 */
public class GSAfficheModAction extends GSBaseAction{

    
    public String execute(GSBaseForm aForm) throws Exception {
        
        GSAfficheForm tForm=(GSAfficheForm)aForm;
        GSAfficheBean tGSAfficheBean=new GSAfficheBean();
        BeanUtils.copyProperties(tGSAfficheBean,tForm);
        
        try{
          if(tForm.getDelfile().equals("2")){
              String tPath=GSSystemConfigurator.getParam("gs.upload.savepath");
              String filename=tGSAfficheBean.getGs_affiche_filename();
              String realFilePath = tPath+"\\"+filename;
              File tOldFile = new File(realFilePath);
              //删除文件
              if (tOldFile.exists() && tOldFile.isFile()){
                  tOldFile.delete();
              }
              tGSAfficheBean.setGs_affiche_filename("");
            //文件上传并保存该文件
            FormFile tFile = tForm.getFilename();
              if(!(tFile.getFileSize() == 0)){
                String tSaveName = tFile.getFileName();
                
                String buf = Long.toString(System.currentTimeMillis()/100); 
            
                String tSaveFileName=tSaveName.substring(0,tSaveName.indexOf("."));
                String tFileType=tSaveName.substring(tSaveName.indexOf("."));
                String tFileName=tSaveFileName+buf+tFileType;
                GSAfficheProcessor.saveFile(tFile,tPath,tFileName);
                tGSAfficheBean.setGs_affiche_filename(tFileName);
               }
            }    
            GSAfficheProcessor.modifyTask(tGSAfficheBean);
        }catch(GSException err){
            HashMap tMap = new HashMap();
            tMap.put("err",err.getMessage());
            aForm.getRequest().setAttribute("_error",tMap);
            aForm.getRequest().setAttribute("message",err.getMessage());
            
            aForm.getRequest().setAttribute("exception_code",err.getCode());
            aForm.getRequest().setAttribute("requery","true");
            throw err;
        }
        aForm.getRequest().setAttribute("backstep", "0");
        aForm.getRequest().setAttribute("message", "修改公告信息成功!");
        aForm.getRequest().setAttribute("requery","true");
        
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
